package cc.chinagps.gateway.unit.eg.upload.cmds;

import org.apache.log4j.Logger;

import cc.chinagps.gateway.log.LogManager;
import cc.chinagps.gateway.unit.UnitServer;
import cc.chinagps.gateway.unit.UnitSocketSession;
import cc.chinagps.gateway.unit.beans.UnitInfo;
import cc.chinagps.gateway.unit.eg.pkg.EGPackage;
import cc.chinagps.gateway.util.HexUtil;

public abstract class CheckLoginHandler implements UploadHandler {
	private Logger logger_others = Logger.getLogger(LogManager.LOGGER_NAME_OTHERS);

	@Override
	public boolean handlerPackage(EGPackage pkg, UnitServer server, UnitSocketSession session) throws Exception {
		UnitInfo unitInfo = session.getUnitInfo();

		if (unitInfo == null) {
			logger_others.info("[EG]unit not login, remote address:" + session.getRemoteAddress() + ", source code:"
					+ HexUtil.byteToHexStr(pkg.getSource()));
			session.close();
			return true;
		}

		return handlerPackageSessionChecked(pkg, server, session);
	}

	public abstract boolean handlerPackageSessionChecked(EGPackage pkg, UnitServer server, UnitSocketSession session)
			throws Exception;
}